SHELL = /bin/sh
VERSION = @PACKAGE_VERSION@
PACKAGE = ate
PACKAGE_DIR = ate
CC = gcc
JAVA_HOME = @JAVA_HOME@
JAVAC = @JAVAC@
JAR = $(JAVA_HOME)/bin/jar
JAVAH = $(JAVA_HOME)/bin/javah
PLATFORM=@PLATFORM@
PREFIX = /usr
CFLAGS = @CFLAGS@ @LIBSWITCH@
JAVA_FLAGS = -g:none -deprecation
NATIVELIB=libunixnetlinksocket
LIBEXT=@LIBEXT@
INCLUDEPATH = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(PLATFORM)

#LIB32=$(NATIVELIB)-$(PLATFORM)-i386.$(LIBEXT)
LIB64=$(NATIVELIB)-$(PLATFORM)-x86_64.$(LIBEXT)
#M32=@M32@
M64=@M64@
JARFILE=jnl-$(VERSION).jar
UNIJARFILE=jnl-$(VERSION)-universal.jar

all: jar 

jar: $(JARFILE)

# requires that the binaries from other platforms are copied here. 
universal: jar
	cp $(JARFILE) $(UNIJARFILE)
	$(JAR) uf $(UNIJARFILE) $(NATIVELIB)-darwin-i386.dylib $(NATIVELIB)-darwin-x86_64.dylib $(NATIVELIB)-linux-x86_64.so

package: universal
	mkdir jnl-$(VERSION)-universal
	cp $(UNIJARFILE) jnl-$(VERSION)-universal
	cp README.md jnl-$(VERSION)-universal
	cp COPYRIGHT jnl-$(VERSION)-universal
	tar pczf jnl-$(VERSION)-universal.tar.gz jnl-$(VERSION)-universal
	rm -rf jnl-$(VERSION)-universal

jnl-$(VERSION).jar: $(PACKAGE_DIR)/UnixNetlinkSocket.class nativelib $(PACKAGE_DIR)/JNL.class
	$(JAR) cf $@ $(PACKAGE_DIR)/*.class $(LIB64)

nativelib: $(PACKAGE_DIR)/UnixNetlinkSocket.c $(PACKAGE_DIR)/UnixNetlinkSocket.h
#	$(CC) $(CFLAGS) -fPIC $(INCLUDEPATH) $(M32) -o $(LIB32) $< 
	$(CC) $(CFLAGS) -fPIC $(INCLUDEPATH) $(M64) -o $(LIB64) $< 

$(PACKAGE_DIR)/UnixNetlinkSocket.h: $(PACKAGE).UnixNetlinkSocket
	$(JAVAH) -o $@ $<

$(PACKAGE).UnixNetlinkSocket: $(PACKAGE_DIR)/UnixNetlinkSocket.class

$(PACKAGE_DIR)/JNL.class: $(PACKAGE_DIR)/JNL.java
	$(JAVAC) $(JAVA_FLAGS) $?

$(PACKAGE_DIR)/UnixNetlinkSocket.class: $(PACKAGE_DIR)/UnixNetlinkSocket.java
	$(JAVAC) $(JAVA_FLAGS) $?


install: nativelib
	cp $(NATIVELIB) $(PREFIX)/lib

uninstall:
	rm -f $(PREFIX)/lib/$(NATIVELIB)

test: test/TestUnixNetlinkSocket.class
	java -cp $(JARFILE):test TestUnixNetlinkSocket

test/TestUnixNetlinkSocket.class: test/TestUnixNetlinkSocket.java jar
	$(JAVAC) -cp $(JARFILE) $(JAVA_FLAGS) $<


clean:
	rm -f $(PACKAGE_DIR)/*.class $(PACKAGE_DIR)/test/*.class $(PACKAGE_DIR)/*.h *.so *.jar test/*class
